﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package net.wooga.pets.views.kindergarten {
    import flash.events.*;
    import flash.display.*;
    import flash.utils.*;
    import net.wooga.pets.views.components.*;
    import reprise.tweens.*;
    import net.wooga.pets.constants.*;
    import net.wooga.pets.utils.*;
    import com.robertpenner.easing.*;

    public class BabyCycleView extends RenderListView {

        public var BOOST_HEADLINE_OFFSET:int = -155
        public var BOOST_TIME_OFFSET:int = -125
        private var _arc:MovieClip;
        private var _boostButton:MovieClip;
        private var _hugButton:MovieClip;
        private var _getButton:MovieClip;
        private var _giveButton:MovieClip;
        private var _findButton:MovieClip;
        private var _hugText:String;
        private var _giveText:String;
        private var _getText:String;
        private var _boostText:String;
        private var _boostHeadlineText:String;
        private var _findText:String;
        private var _findFamilyText:String;
        private var _parentsContainer:MovieClip;
        private var _boostBubble:MovieClip;
        private var _clockAnimation:MovieClip;
        private var _boostBubbleHeadline:DynamicTF;
        private var _boostTime:DynamicTF;
        private var _textAnimation:MovieClip;
        private var _textAnimationText:String;
        private var _textAnimationTF:DynamicTF;
        private var _oldTreatmentTime:int;
        private var _newTreatmentTime:int;
        private var _boostAnimationTimer:Timer;

        private static const HUG_BAR_WIDTH:int = 172;
        private static const TEXTANIMATION_FONTCOLOR:String = "0xFFE046";
        private static const TEXTANIMATION_FONTSIZE:int = 24;
        private static const BOOSTTIME_FONTCOLOR:String = "0xf94034";
        private static const BOOSTTIME_FONTSIZE:int = 30;
        private static const ADOBT_FONTCOLOR:String = "0x663300";
        private static const ADOPT_FONTSIZE:int = 24;
        private static const BOOST_BUBBLE_OFFSET:int = -130;
        private static const CLOCK_ANIMATION_OFFSET:int = -160;
        private static const BOOST_BUTTON_OFFSET:int = -90;
        private static const ARC_OFFSET:int = 60;

        private static var _cycleContainer:MovieClip;

        public function BabyCycleView():void{
        }
        public function init():void{
            _cycleContainer = AssetsLibrary.getMovieClip("BC_CycleConatainer");
            _cycleContainer.scaleX = (_cycleContainer.scaleY = 1.5);
            _cycleContainer.visible = false;
            _cycleContainer.bg.useHandCursor = false;
            addChild(_cycleContainer);
            this._hugButton = _cycleContainer.hugButton;
            this._hugButton.buttonMode = true;
            this._hugButton.mouseChildren = false;
            this._hugButton.addEventListener(MouseEvent.MOUSE_OVER, this.onMouseOver);
            this._hugButton.addEventListener(MouseEvent.MOUSE_OUT, this.onMouseOut);
            this._hugButton.visible = true;
            this._boostButton = AssetsLibrary.getMovieClip("BC_BoostButton");
        }
        public function initBoostbubble():void{
            this._boostBubble = AssetsLibrary.getMovieClip(SpeechBubbleConstants.ICON_BABY_BOOST);
            this._boostBubble.y = BOOST_BUBBLE_OFFSET;
            _cycleContainer.addChild(this._boostBubble);
            this._boostBubbleHeadline = new DynamicTF();
            this._boostBubbleHeadline.htmlText = this._boostHeadlineText;
            this._boostBubbleHeadline.x = (-(this._boostBubbleHeadline.width) / 2);
            this._boostBubbleHeadline.y = this.BOOST_HEADLINE_OFFSET;
            this._boostBubble.addChild(this._boostBubbleHeadline);
            this._boostTime = new DynamicTF(BOOSTTIME_FONTCOLOR, BOOSTTIME_FONTSIZE);
            this._boostTime.htmlText = "";
            this._boostTime.x = (-(this._boostTime.width) / 2);
            this._boostTime.y = this.BOOST_TIME_OFFSET;
            this._boostBubble.addChild(this._boostTime);
            this.setButtonText(this._boostText, this._boostButton);
            this._boostButton.x = (-(this._boostButton.width) / 2);
            this._boostButton.y = BOOST_BUTTON_OFFSET;
            this._boostBubble.addChild(this._boostButton);
            this._clockAnimation = AssetsLibrary.getMovieClip("Icons_ClockAnimation");
            this._clockAnimation.scaleX = (this._clockAnimation.scaleY = 1.5);
            this._clockAnimation.x = ((this._boostBubble.bg.width / 2) - ((3 * this._clockAnimation.width) / 4));
            this._clockAnimation.y = CLOCK_ANIMATION_OFFSET;
            this._boostBubble.addChild(this._clockAnimation);
            this._boostButton.buttonMode = true;
            this._boostButton.mouseChildren = false;
            this._boostButton.addEventListener(MouseEvent.MOUSE_OVER, this.onMouseOver);
            this._boostButton.addEventListener(MouseEvent.MOUSE_OUT, this.onMouseOut);
            this._textAnimationTF = new DynamicTF(TEXTANIMATION_FONTCOLOR, TEXTANIMATION_FONTSIZE, [Filters.getFilter(Filters.TEXT_OUTLINE_BROWN)], "ShowcardGothic");
            this._textAnimationTF.htmlText = this._textAnimationText;
            this._textAnimation = AssetsLibrary.getMovieClip("Icons_BoostTextAnimation");
            this._textAnimation.animationText.addChild(this._textAnimationTF);
            this._textAnimation.x = (-(this._textAnimation.width) / 2);
            this._textAnimation.mouseChildren = false;
            this._textAnimation.mouseEnabled = false;
            this._boostBubble.visible = false;
            this._boostBubble.addChild(this._textAnimation);
        }
        public function showCycle():void{
            var _local1:SimpleTween;
            show();
            _cycleContainer.visible = true;
            if (_cycleContainer.alpha == 0){
                _local1 = new SimpleTween(200);
                _local1.addTweenProperty(_cycleContainer, "alpha", _cycleContainer.alpha, 1, Quad.easeIn);
                _local1.execute();
            };
        }
        public function hideCycle():void{
            var _local1:SimpleTween = new SimpleTween(100);
            _local1.addTweenProperty(_cycleContainer, "alpha", _cycleContainer.alpha, 0, Quad.easeIn);
            _local1.addEventListener(Event.COMPLETE, this.onHideComplete);
            _local1.execute();
        }
        private function onHideComplete(_arg1:Event):void{
            _cycleContainer.visible = false;
        }
        public function setHugBar(_arg1:Number, _arg2:Boolean=true):void{
            var _local4:SimpleTween;
            _arg1 = Math.max(_arg1, 0);
            var _local3:Number = (-(HUG_BAR_WIDTH) + ((_arg1 / 100) * HUG_BAR_WIDTH));
            if (_arg2){
                _local4 = new SimpleTween(500);
                _local4.addTweenProperty(this._hugButton.bar, "x", this._hugButton.bar.x, _local3, Quad.easeInOut);
                _local4.execute();
            } else {
                this._hugButton.bar.x = _local3;
            };
        }
        public function addCircle(_arg1:int):void{
            if (((((this._arc) && ((_cycleContainer.numChildren > 0)))) && (!((_cycleContainer.getChildIndex(this._arc) == -1))))){
                _cycleContainer.removeChild(this._arc);
            };
            this._arc = AssetsLibrary.getMovieClip(("BC_Arc_" + _arg1));
            this._arc.y = ARC_OFFSET;
            _cycleContainer.addChild(this._arc);
            var _local2:DynamicTF = new DynamicTF(ADOBT_FONTCOLOR, ADOPT_FONTSIZE, [Filters.getFilter(Filters.TEXT_OUTLINE)]);
            _local2.htmlText = this._findFamilyText;
            this._parentsContainer = this._arc[("t" + (_arg1 - 1))].parentsContainer;
            _local2.x = ((this._parentsContainer.width / 2) - (_local2.width / 2));
            _local2.y = ((this._parentsContainer.height / 2) - (_local2.height / 2));
            this._parentsContainer.buttonMode = true;
            this._parentsContainer.addChild(_local2);
            this._findButton = this._parentsContainer.findButton;
            this._findButton.visible = false;
            this.setButtonText(this._findText, this._findButton);
        }
        public function setTreatment(_arg1:int, _arg2:String, _arg3:Function=null, _arg4:Function=null):void{
            var _local5:MovieClip = (this._arc[("t" + _arg1)] as MovieClip);
            _local5.numbers.gotoAndStop((_arg1 + 1));
            _local5.gotoAndStop(_arg2);
            _local5.buttonMode = false;
            this._getButton = _local5.getButton;
            this._getButton.buttonMode = true;
            this._getButton.visible = false;
            this.setButtonText(this._getText, this._getButton);
            this._giveButton = _local5.giveButton;
            this._giveButton.buttonMode = true;
            this._giveButton.visible = false;
            this.setButtonText(this._giveText, this._giveButton);
            if (_arg3 != null){
                this.addMouseListeners(_local5, _arg3);
                this._giveButton.visible = true;
                _local5.buttonMode = true;
            } else {
                if (_arg4 != null){
                    this.addMouseListeners(_local5, _arg4);
                    this._getButton.visible = true;
                    _local5.buttonMode = true;
                };
            };
        }
        public function showFindParents(_arg1:Function):void{
            this._findButton.visible = true;
            this.addMouseListeners(this._parentsContainer, _arg1);
        }
        private function addMouseListeners(_arg1:MovieClip, _arg2:Function):void{
            _arg1.addEventListener(MouseEvent.CLICK, _arg2);
            _arg1.addEventListener(MouseEvent.ROLL_OVER, this.onRollOverButton);
            _arg1.addEventListener(MouseEvent.ROLL_OUT, this.onRollOutButton);
        }
        private function onMouseOver(_arg1:MouseEvent):void{
            var _local2:MovieClip = (_arg1.target as MovieClip);
            _local2.gotoAndStop("over");
        }
        private function onMouseOut(_arg1:MouseEvent):void{
            var _local2:MovieClip = (_arg1.target as MovieClip);
            _local2.gotoAndStop("out");
        }
        private function onRollOutButton(_arg1:MouseEvent):void{
            if (_arg1.target.greenCircle){
                _arg1.target.greenCircle.gotoAndStop("out");
            };
            var _local2:MovieClip = this.getTargetButton((_arg1.target as MovieClip));
            _local2.bg.gotoAndStop("default");
        }
        private function onRollOverButton(_arg1:MouseEvent):void{
            if (_arg1.target.greenCircle){
                _arg1.target.greenCircle.gotoAndStop("over");
            };
            var _local2:MovieClip = this.getTargetButton((_arg1.target as MovieClip));
            _local2.bg.gotoAndStop("hover");
        }
        private function getTargetButton(_arg1:MovieClip):MovieClip{
            if (((_arg1.giveButton) && (_arg1.giveButton.visible))){
                return (_arg1.giveButton);
            };
            if (((_arg1.getButton) && (_arg1.getButton.visible))){
                return (_arg1.getButton);
            };
            return (_arg1.findButton);
        }
        private function setButtonText(_arg1:String, _arg2:MovieClip):void{
            var _local3:DynamicTF = new DynamicTF("0xffffff", 24);
            _local3.htmlText = _arg1;
            Displays.removeAllChildren(_arg2.tf);
            _arg2.tf.addChild(_local3);
        }
        public function setTimeText(_arg1:int):void{
            _arg1 = Math.max(_arg1, 0);
            var _local2:String = TimeUtils.secondsToHoursMinSec(_arg1);
            this._boostTime.htmlText = _local2;
        }
        public function startBoostAnimations(_arg1:int, _arg2:int):void{
            this.stopTextAnimation();
            this._clockAnimation.gotoAndPlay("tick");
            this._textAnimation.gotoAndPlay("start");
            this._oldTreatmentTime = _arg1;
            this._newTreatmentTime = _arg2;
            this.playBoostAnimation();
        }
        private function playBoostAnimation():void{
            this._boostAnimationTimer = new Timer(50, 20);
            this._boostAnimationTimer.addEventListener(TimerEvent.TIMER, this.timeAnimationTick);
            this._boostAnimationTimer.addEventListener(TimerEvent.TIMER_COMPLETE, this.timeAnimationComplete);
            this._boostAnimationTimer.start();
        }
        private function stopTextAnimation():void{
            if (((this._boostAnimationTimer) && (this._boostAnimationTimer.running))){
                this._boostAnimationTimer.removeEventListener(TimerEvent.TIMER, this.timeAnimationTick);
                this._boostAnimationTimer.removeEventListener(TimerEvent.TIMER_COMPLETE, this.timeAnimationComplete);
                this._boostAnimationTimer.stop();
            };
        }
        private function timeAnimationTick(_arg1:TimerEvent):void{
            var _local2:int = (this._oldTreatmentTime - (((this._oldTreatmentTime - this._newTreatmentTime) / this._boostAnimationTimer.repeatCount) * this._boostAnimationTimer.currentCount));
            this.setTimeText(_local2);
        }
        private function timeAnimationComplete(_arg1:TimerEvent):void{
            var _local2:int = (this._newTreatmentTime - 1);
            this.stopTextAnimation();
            this.setTimeText(_local2);
        }
        public function get cycleContainer():MovieClip{
            return (_cycleContainer);
        }
        public function set hugText(_arg1:String):void{
            this._hugText = _arg1;
            this.setButtonText(this._hugText, this._hugButton);
        }
        public function set giveText(_arg1:String):void{
            this._giveText = _arg1;
        }
        public function set getText(_arg1:String):void{
            this._getText = _arg1;
        }
        public function set boostText(_arg1:String):void{
            this._boostText = _arg1;
        }
        public function set findFamilyText(_arg1:String):void{
            this._findFamilyText = _arg1;
        }
        public function get boostButton():MovieClip{
            return (this._boostButton);
        }
        public function get hugButton():MovieClip{
            return (this._hugButton);
        }
        public function set findText(_arg1:String):void{
            this._findText = _arg1;
        }
        public function get boostBubble():MovieClip{
            return (this._boostBubble);
        }
        public function set boostHeadlineText(_arg1:String):void{
            this._boostHeadlineText = _arg1;
        }
        public function get arc():MovieClip{
            return (this._arc);
        }
        public function set textAnimationText(_arg1:String):void{
            this._textAnimationText = _arg1;
        }

    }
}//package net.wooga.pets.views.kindergarten 
